package gravitron;

import java.util.logging.*;

public class Grav_Object extends Sprite{
	//variables
	Logger logger= Logger.getLogger(Grav_Object.class.getName());
	//distance to click, null if no previous click
	private float dist;
	//theta to click with reference to x axis
	private float theta;
	//velocity
	private float vel;
	//acceleration
	private float acc;
	//mass, this is for the inertia of the object
	private float mass;
	//feels gravity, gravity acting on object
	boolean is_grav=false;
	//time since gravity started, really, number of updates called 
	int time_since_grav=0;
	int grav_loc_x;
	int grav_loc_y;
	
	
	/**@return the c_x*/
	
	public Grav_Object(float c_xi, float c_yi, int s_xi, int s_yi, float massi){
		super(c_xi, c_yi, s_xi, s_yi);
		setVel(0);
		setAcc(0);
		setMass(massi);
		logger.setLevel(Level.OFF);
		logger.info("Created with x coord: "+getUp_left_x()+" y coord: "+getUp_left_y()+
				" size_x "+getSize_x()+" size_y "+getSize_y()+" mass: "+mass);
	}
	
	
	public void update(){
		if (is_grav){
			
			acc=(float) (1.0/(1.0*mass*Math.pow(dist, 1.5)));
//			logger.info("mass "+mass+" distance^2 "+Math.pow(dist, 2));
			vel += acc;
			logger.info("acc "+acc+" vel "+vel);
			super.setUp_left_x((float) (super.getUp_left_x()+vel*Math.cos(theta)));
			super.setUp_left_y((float) (super.getUp_left_y()+vel*Math.sin(theta)));

			logger.info("sin(theta) "+Math.sin(theta));
//			super.setUp_right_x(())
		}else{
			if (vel>.2){
			vel -= .2;
			}else{vel=0;}
			
			logger.info("acc "+acc+" vel "+vel);
			super.setUp_left_x((float) (super.getUp_left_x()+vel*Math.cos(theta)));
			super.setUp_left_y((float) (super.getUp_left_y()+vel*Math.sin(theta)));
			
		}
//		logger.info("updating");
	}


	
	/**@return the dist*/
	
	public float getDist() {
		return dist;
	}
	/**@param dist the dist to set*/
	public void setDist(float dist) {
		this.dist = dist;
	}
	/**@return the theta*/
	
	public float getTheta() {
		return theta;
	}
	/**@param theta the theta to set*/
	public void setTheta(float theta) {
		this.theta = theta;
	}
	/**@return the vel*/
	
	public float getVel() {
		return vel;
	}
	/**@param vel the vel to set*/
	public void setVel(float vel) {
		this.vel = vel;
	}
	/**@return the acc*/
	
	public float getAcc() {
		return acc;
	}
	/**@param acc the acc to set*/
	public void setAcc(float acc) {
		this.acc = acc;
	}
	/**@return the mass*/
	
	public float getMass() {
		return mass;
	}
	/**@param mass the mass to set*/
	public void setMass(float mass) {
		this.mass = mass;
	}


	/**@return the is_grav*/
	
	public boolean isIs_grav() {
		return is_grav;
	}


	/**@param is_grav the is_grav to set*/
	public void setIs_grav(boolean is_gravi) {
		if (!is_gravi){
			acc=0;
//			vel=0;
			time_since_grav=0;
			logger.info("is_grav set to false");
		}
		this.is_grav = is_gravi;
	}
	
	public void incrementTime_since_grav(){
		time_since_grav+=1;
	}
	
	/**@param up_left_x the up_left_x to set*/
	public void setUp_left_x(float up_left_xi) {
		//if (it is within boundaries and boundaries are on) update x
		//or if (its boundaries are not on) update x
		if ((up_left_xi>=0 && up_left_xi<=bound_x && isBound_by_frame) || (!isBound_by_frame)){
			super.setUp_left_x(up_left_xi);
		}else{
			logger.fine("boundaries preventing x component update at "+up_left_xi);
			setTheta((float) (getTheta()+Math.PI));
		}

	}
	
	
	
	//Methods
	
	
	
}
